#include "MySQLWorker.h"
#include "BlockingQueue.hpp"
#include "SqlOperation.h"

void MySQLWorker::Start()
{
    thread_ = std::thread(&MySQLWorker::worker,this);
}

void MySQLWorker::Close(){
    if (thread_.joinable())
    {
        thread_.join();
    }
}

void MySQLWorker::worker(){
    while (true)
    {
        SqlOperation* opr = nullptr;
        if (!task_queue_.Pop(opr))
        {
            break;
        }
        opr->ExecuteSql(obj_);
        delete opr;
    }
}